package com.ycy.chuwenuniapp.utils;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ycy.chuwenuniapp.common.Constant;


public class WeiXinUtils {
    // public static void main(String[] args) {
    //     // getAccessToken();
    //     // getQrCodeTicket();
    // }

    //获取普通AccessToken
    public static JSONObject getAccessToken() {
        String url = Constant.GET_ACCESS_TOKEN_URL.replace("APPID",Constant.APP_ID).replace("APPSECRET",Constant.APP_SECRET);
        String result = HttpUtil.get(url);
        System.out.println("获取access_token结果："+ result);
        return JSON.parseObject(result);  //通过res.get("access_token").toString();获取

        // {"access_token":"68_fv1jZIOZ9y3kfUuUt2g0jfVnWmAZ3aDcplHzwN23b4Q4eLAYifvpYdBWgltXnTHPIWKVFNELkwuGeYz5I1gRRskxALuIpg0iJQS1EeCgKI9OIKpgCrxw6IUNsPIPFViAAAZPF","expires_in":7200}
    }

    //获取带场景值的二维码的ticket和二维码所跳转的链接
    public static String getQrCodeTicketAndUrl(String accessToken,String postData) {
        // String postData = "{\"expire_seconds\": 2592000,\"action_name\": \"QR_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": 123}}}";
        // String accessToken = "68_fv1jZIOZ9y3kfUuUt2g0jfVnWmAZ3aDcplHzwN23b4Q4eLAYifvpYdBWgltXnTHPIWKVFNELkwuGeYz5I1gRRskxALuIpg0iJQS1EeCgKI9OIKpgCrxw6IUNsPIPFViAAAZPF";
        String url = Constant.POST_QR_CODE_TICKET_URL.replace("TOKEN",accessToken);
        String result = HttpUtil.post(url,postData);
        System.out.println("获取场景值二维码ticket结果："+ result);
        return result;
        // 结果示例
        // {"ticket":"gQFI8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAySXJoZFFoMENlcUMxdVQ5TXhBMVcAAgS3PElkAwQAjScA",
        // "expire_seconds":2592000,"url":"http:\/\/weixin.qq.com\/q\/02IrhdQh0CeqC1uT9MxA1W"}
        // 然后用imageUtils中的生成二维码方法生成跳转该url的码
    }
}
